Passed
Push — master ( 8f169b...36019d )
by Rafael
01:27
created

control.js ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
nc 1
dl 0
loc 3
rs 10
cc 1
nop 0
1
import './style.scss';
2
import templateHTML from './template.html';
3
import { Storage } from '../storage';
4
5
export class Control {
6
	constructor() {
7
		this.storage = new Storage();
8
	}
9
10
	getItem( settingName ) {
11
		return this.storage.getItem( settingName );
12
	}
13
14
	render() {
15
		this.$control = $( templateHTML );
16
		this.$save = this.$control.find( '.save-settings' );
17
		this.$clear = this.$control.find( '.clear-storage' );
18
19
		$( 'save-ui' ).replaceWith( this.$control );
20
	}
21
22
	setup( settingName, getValueCb ) {
23
		this.$save.on( 'click', () => {
24
			this.storage.setItem( settingName, getValueCb( settingName ) );
25
			setTimeout( () => location.reload() );
26
		} );
27
28
		this.$clear.on( 'click', () => {
29
			this.storage.removeItem( settingName );
30
			setTimeout( () => location.reload() );
31
		} );
32
	}
33
}
34